<!--

    This file is part of kanji-portal.com.

    kanji-portal.com is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    kanji-portal.com is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with kanji-portal.com.  If not, see <http://www.gnu.org/licenses/>.

    Copyright (c) 2008-2009 Nicolas Radde <nicolas@radde.org>

-->
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:a="http://richfaces.org/a4j"
                xmlns:s="http://jboss.com/products/seam/taglib"
                template="#{theme.template}">

    <!-- content -->
    <ui:define name="content">
        <a:outputPanel id="messages">
            <div class="errors">
                <h:messages/>
            </div>
        </a:outputPanel>
        <fieldset>
            <legend>Modify users and roles</legend>
            <h:form id="modifyUsersRoles">
                <p>
                    <h:inputText id="username" label="pouet" value="#{userManagement.username}"/>
                    <h:inputSecret id="password" value="#{userManagement.password}"/>
                    <a:status id="sUser" forceId="true">
                        <f:facet name="start">
                            <h:graphicImage value="#{theme.spinner}"/>
                        </f:facet>
                    </a:status>
                    <br/>
                    <a:commandButton id="addUser" value="Add User"
                                     action="#{userManagement.createUser}"
                                     reRender="panelUsers" status="sUser"/>
                    <br/>
                    <h:inputText id="role" value="#{userManagement.role}"/>
                    <a:status id="sRole" forceId="true">
                        <f:facet name="start">
                            <h:graphicImage value="#{theme.spinner}"/>
                        </f:facet>
                    </a:status>
                    <br/>
                    <a:commandButton id="addRole" value="Add Role"
                                     action="#{userManagement.createRole}"
                                     reRender="panelRoles" status="sRole"/>
                    <br/>
                    <h:inputText id="usernameGrant" value="#{userManagement.username}"/>
                    <h:inputText id="roleGrant" value="#{userManagement.role}"/>
                    <a:status id="sGrant" forceId="true">
                        <f:facet name="start">
                            <h:graphicImage value="#{theme.spinner}"/>
                        </f:facet>
                    </a:status>
                    <br/>
                    <a:commandButton id="grantRole" value="Grant Role"
                                     action="#{userManagement.grantRole}"
                                     reRender="panelSelectedUser" status="sGrant"/>
                </p>
            </h:form>
        </fieldset>
        <a:outputPanel id="panelSelectedUser">
            <fieldset id="selectedUser">
                <legend>User #{selectedUser}</legend>
                <ui:repeat var="tRole" value="#{userRoles}">
                    #{tRole}
                </ui:repeat>
            </fieldset>
        </a:outputPanel>
        <a:outputPanel id="panelUsers">
            <fieldset id="users">
                <legend>List of users</legend>
                <h:dataTable var="tUser" value="#{users}">
                    <h:column>
                        <f:facet name="col1"/>
                        <a:commandLink value="#{tUser}" action="#{userManagement.selectUser}"
                                       reRender="panelSelectedUser"/>

                    </h:column>
                </h:dataTable>
            </fieldset>
        </a:outputPanel>
        <a:outputPanel id="panelRoles">
            <fieldset id="roles">
                <legend>List of roles</legend>
                <ui:repeat var="tRole" value="#{roles}">
                    #{tRole}
                </ui:repeat>
            </fieldset>
        </a:outputPanel>
    </ui:define>

</ui:composition>
